package com.healthsystem.portplay.controller;

import com.healthsystem.portplay.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class UpDateController {

    private final UserDao userDao;

    @Autowired
    public UpDateController(UserDao userDao) {
        this.userDao = userDao;
    }

    // 更新用户状态的接口方法
    @PutMapping("/updateState")
    public String updateUserState(@RequestBody UpdateStateRequest request) {
        String username = request.getUsername();
        boolean newState = request.getState();


        // 在这里根据用户名更新数据库中的用户状态
        userDao.updateUserState(username, newState);


        return "User state updated successfully";
    }

    // 更新状态请求的请求体
    public static class UpdateStateRequest {
        private String username;
        private boolean state;

        public String getUsername() {
            return username;
        }

        public void setUsername(String username) {
            this.username = username;
        }

        public boolean getState() {
            return state;
        }

        public void setState(boolean state) {
            this.state = state;
        }
    }
}
